package day17.udp;

import lombok.SneakyThrows;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class Server {
    @SneakyThrows
    public static void main(String[] args) {
        // 创建服务器对象，并监听在9527端口
        try(DatagramSocket datagramSocket = new DatagramSocket(9527)) {
            // 接受数据的字节数组
            byte[] data = new byte[1024];
            // 创建数据包
            DatagramPacket packet = new DatagramPacket(data, data.length);
            // udp接受数据包
            System.out.println("udp服务已经启动，等待连接中...");
            datagramSocket.receive(packet);
            String message = new String(data, 0, packet.getLength());
            System.out.println("接收到客户端的数据：" + message);
        }
    }
}
